<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="检测阶别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['checkGrade']" placeholder="请输入检测阶别"></a-input>
        </a-form-item>
        <a-form-item label="项目代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['projectCode']" placeholder="请输入项目代码"></a-input>
        </a-form-item>
        <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['projectName']" placeholder="请输入项目名称"></a-input>
        </a-form-item>
        <a-form-item label="项目类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['projectType']" placeholder="请输入项目类型"></a-input>
        </a-form-item>
        <a-form-item label="管控方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['controlManner']" placeholder="请输入管控方式"></a-input>
        </a-form-item>
        <a-form-item label="上限值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['upLimit']" placeholder="请输入上限值"></a-input>
        </a-form-item>
        <a-form-item label="下限值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['downLimit']" placeholder="请输入下限值"></a-input>
        </a-form-item>
        <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['unit']" placeholder="请输入单位"></a-input>
        </a-form-item>
        <a-form-item label="检测方法" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['checkWay']" placeholder="请输入检测方法"></a-input>
        </a-form-item>
        <a-form-item label="检测顺序" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['checkSequence']" placeholder="请输入检测顺序"></a-input>
        </a-form-item>
        <a-form-item label="默认方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['defaultManner']" placeholder="请输入默认方式"></a-input>
        </a-form-item>
        <a-form-item label="检测内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['checkContent']" placeholder="请输入检测内容"></a-input>
        </a-form-item>
        <a-form-item label="所属部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['query2']" :trigger-change="true" dictCode="check_project_depart" placeholder="请选择所属部门"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "MesCheckprojectInfoModal",
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/inspect/mesMaterielCheckprojrct/addMesCheckprojectInfo",
          edit: "/inspect/mesMaterielCheckprojrct/editMesCheckprojectInfo",
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','sysOrgCode','checkGrade','projectCode','projectName','projectType','controlManner','upLimit','downLimit','unit','checkWay','checkSequence','defaultManner','checkContent','mcheckprojectId','query2','query3','query4','query5','query6'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            formData['mcheckprojectId'] = this.mainId
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }

        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','sysOrgCode','checkGrade','projectCode','projectName','projectType','controlManner','upLimit','downLimit','unit','checkWay','checkSequence','defaultManner','checkContent','mcheckprojectId','query2','query3','query4','query5','query6'))
      },


    }
  }
</script>
